<!DOCTYPE html>
<html lang="en">
<!--<script src="myscript.js"></script>-->
<head>
    <meta charset="UTF-8">
    <title>js表单</title>
    <script type="text/javascript">

        document.write("<h1> 这是一个简介 </h1>")
        document.write("<h1> 这也是一个简介 </h1>")

    </script>
</head>
<body>
<button type="button" onclick="alert('hello world')">点击我</button>
<form name="myForm" action="" onsubmit="return validateForm()" method="post">
    名字: <label><input type="text" name="fname"></label>
    <input type="submit" value="提交">
</form>


<label>请输入数字：<input id="id1" type="number" min="100" max="300"></label>
<button type="button" onclick="validateNum()">提交</button>
<p id="demo"></p>

<script>
    /*function validateForm() {
        var x = document.forms["myForm"]["fname"].value;
        // if (x == null || x === "") {
        //     alert("需要输入名字。");
        //     return false;
        // }
        if (isNaN(x) || !(x >= 1 && x <= 10)) {
            alert("输入数据要在1-10之间")
            return false
        }
    }*/
    function validateNum() {
        var x = document.getElementById("id1")
        var y = x.value
        if (x.checkValidity() === false) {
            document.getElementById("demo").innerText = x.validationMessage;
        }else{
            document.getElementById("demo").innerText = y
        }

    }
    res = JSON.parse('{"a": 1, "b": 2}')
    console.log(res)
</script>
</body>
</html>